<?php
if (!defined('__COLA_DIR__')) exit;

/**
 * Widget_Plugins_Ucenter  
 * 
 * @author edikud
 * @package Widget
 * @copyright Copyright (c) 2019 Cola (http://www.mcooo.com)
 * @license GNU General Public License 2.0
 */
class Widget_Plugins_Ucenter extends Widget_Abstract_Options
{
	
    /**
     * 执行函数
     *
     * @access public
     * @return void
     */
    public function execute()
    {
		$this->user->pass('admin');
    }
    public function pluginsList()
    {

        $this->widget('Widget_Scripts')->set("
            $(document).ready(function () {
			    $(\".cola-content\").ajaxClick('.deactivate,.activate');
		});", 'Widget_Plugins_List');

		$this->widget('Widget_Plugins_List@activated', 'activated=1')->to($activatedPlugins);
		$html = '';
		
        if ($activatedPlugins->have() || !empty($activatedPlugins->activatedPlugins)) {
			$Layout = new Layout();
			$Layout->prepend('<h2>'._t('启用的插件').'</h2>');
			$Layout->header(array(
			    _t('名称'),
				_t('描述') . ' - ' . _t('作者') . ' (' . _t('版本') . ')',
				_t('操作')
			));
			while ($activatedPlugins->next()){
			    $Layout->lists(array(
				    $activatedPlugins->name . (!$activatedPlugins->dependence ? _t('%s 无法在此版本的cola下正常工作', $activatedPlugins->title) : ''),
					'<div class="text-muted text-md">' . $activatedPlugins->description . ' - ' .
					(empty($activatedPlugins->homepage) ? $activatedPlugins->author : '<a href="' . $activatedPlugins->homepage . '">' . $activatedPlugins->author . '</a>'). ' ( v' . $activatedPlugins->version . ' )</div>',
					
					($activatedPlugins->config ? '<a class="cola-button text-md" href="'.$this->options->ucenterUrl('options-plugin?config=' . $activatedPlugins->name, false).'">'._t('设置').'</a>&nbsp;&nbsp;' : '') . '<a class="cola-button deactivate text-md" data-loading-text="loading.." data-confirm="'._t('你确认要禁用插件 %s 吗?', $activatedPlugins->name).'" href="'.$this->security->actionUrl('plugins-edit?deactivate=' . $activatedPlugins->name, 0).'">'._t('禁用').'</a>'
					
					
				), array('id'=>'plugin-'. $activatedPlugins->name));
			}
			
            if (!empty($activatedPlugins->activatedPlugins)){
                foreach ($activatedPlugins->activatedPlugins as $key => $val){
                    $Layout->row(array(
					    $key,
					    _t('此插件文件已经损坏或者被不安全移除, 强烈建议你禁用它'),
						'<a data-confirm="'._t('你确认要禁用插件 %s 吗?', $key).'" href="'.$this->security->actionUrl('plugins-edit?deactivate=' . $key, 0).'">'._t('禁用').'</a>'
					
					));
                }
            } 
			$html .= $Layout->render();
		}

        $this->widget('Widget_Plugins_List@unactivated', 'activated=0')->to($disabledPlugins);
        if ($disabledPlugins->have() || !$activatedPlugins->have()){
			$Layout = new Layout();
			$Layout->prepend('<h2 style="margin-top:50px;">'._t('禁用的插件').'</h2>');

            if ($disabledPlugins->have()){
			    $Layout->header(array(
			        _t('名称'),
				    _t('描述') . ' - ' . _t('作者') . ' (' . _t('版本') . ')',
				    _t('操作')
			    ));	

                while ($disabledPlugins->next()){
					
			        $Layout->lists(array(
				        $disabledPlugins->name,
					    '<div class="text-muted text-md">' . $disabledPlugins->description . ' - ' .
					    (empty($disabledPlugins->homepage) ? $disabledPlugins->author : '<a href="' . $disabledPlugins->homepage . '">' . $disabledPlugins->author . '</a>'). ' ( v' . $disabledPlugins->version . ' )</div>',
					    '<a class="cola-button activate text-md" data-loading-text="loading.." href="'.$this->security->actionUrl('plugins-edit?activate=' . $disabledPlugins->name, 0).'">'._t('启用').'</a>'
				    ), array('id'=>'plugin-'. $disabledPlugins->name));
                }
            } else{
			    $Layout->lists('<h6>'._t('没有安装插件').'</h6>');
            }
            $html .= $Layout->render();
		}

		return $html;
	}
}

